﻿//-----------------------------------------------------------------------
// <copyright>
// This file is subject to the terms and conditions of the Microsoft Public License (MS-PL).
// See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL for more details.
// </copyright>
//----------------------------------------------------------------------- 
using System.Linq;
using System.Reflection;
using Fulcrum.DispatcherProxies;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Fulcrum.UnitTests.DispatcherProxies
{
    [TestClass]
    public class DispatcherProxyGenerationUnitTests
    {
        public DispatcherProxyGenerationUnitTests()
        {
            // nothing
        }

        DispatcherProxyGenerationUnit generationUnit;

        [TestInitialize]
        public void TestInitialize()
        {
            this.generationUnit = new DispatcherProxyGenerationUnit();

            var settings = (DispatcherProxySettings)this.generationUnit.Settings;
            settings.TargetAssembly = Assembly.GetExecutingAssembly().Location;
        }

        [TestMethod]
        public void TestDispatcherProxyGenerationUnitCreateDataContexts()
        {
            Assert.IsNull(this.generationUnit.DataContexts);

            this.generationUnit.CreateDataContexts();

            Assert.IsNotNull(this.generationUnit.DataContexts);
        }

        [TestMethod]
        public void TestDispatcherProxyGenerationUnitDataContexts()
        {
            this.generationUnit.CreateDataContexts();

            Assert.IsNotNull(this.generationUnit.DataContexts);
            Assert.AreEqual(7, this.generationUnit.DataContexts.Count);

            Assert.AreEqual("Fulcrum.UnitTests.DispatcherProxies.Base", this.generationUnit.DataContexts.ElementAt(0).Name);
            Assert.AreEqual("Fulcrum.UnitTests.DispatcherProxies.Derived", this.generationUnit.DataContexts.ElementAt(1).Name);
            Assert.AreEqual("Fulcrum.UnitTests.DispatcherProxies.DoubleDerived", this.generationUnit.DataContexts.ElementAt(2).Name);
            Assert.AreEqual("Fulcrum.UnitTests.DispatcherProxies.MyDispatcherClass", this.generationUnit.DataContexts.ElementAt(3).Name);
            Assert.AreEqual("Fulcrum.UnitTests.DispatcherProxies.MyOtherDispatcherClass", this.generationUnit.DataContexts.ElementAt(4).Name);
            Assert.AreEqual("Fulcrum.UnitTests.DispatcherProxies.PublicDispatcherObjectDecendant", this.generationUnit.DataContexts.ElementAt(5).Name);
            Assert.AreEqual("System.Windows.Threading.DispatcherObject", this.generationUnit.DataContexts.ElementAt(6).Name);
        }

        [TestMethod]
        public void TestDispatcherProxyGenerationUnitName()
        {
            Assert.AreEqual("DispatcherProxy", this.generationUnit.Name);
        }

        [TestMethod]
        public void TestDispatcherProxyGenerationUnitSettings()
        {
            Assert.IsNotNull(this.generationUnit.Settings);
            Assert.IsInstanceOfType(this.generationUnit.Settings, typeof(DispatcherProxySettings));
        }

    }
}
